package org.jiuling.aliyun.sms.convert;

import org.jiuling.aliyun.config.exception.AliYunConfigRuntimeException;
import org.jiuling.aliyun.sms.model.QuerySmsSignResponseModel;
import org.jiuling.aliyun.sms.model.enums.SendStatusEnum;
import org.jiuling.basics.converter.DateConvert;
import org.jiuling.basics.enums.DateTimeFormatEnum;
import org.jiuling.basics.exception.BasicsException;
import org.jiuling.basics.util.EnumUtil;
import org.jiuling.basics.validation.IntegerVerify;
import org.jiuling.basics.validation.StringVerify;

/**
 * 查询短信签名响应转换
 * @author 紫灵
 * @date 2023年02月21日 14时20分16秒
 */
public class QuerySmsSignResponseConvert {

    /** 私有构造方法，禁止创建对象 */
    private QuerySmsSignResponseConvert() {}

    /**
     * 内容转模型
     * @param querySmsSignResponseBody 获取短信签名响应内容
     * @return 获取短信签名响应模型
     */
    public static QuerySmsSignResponseModel bodyToModel(com.aliyun.sdk.service.dysmsapi20170525.models.QuerySmsSignResponseBody querySmsSignResponseBody){
        QuerySmsSignResponseModel querySmsSignResponseModel = new QuerySmsSignResponseModel();
        querySmsSignResponseModel.setReason(querySmsSignResponseBody.getReason());
        querySmsSignResponseModel.setSignName(querySmsSignResponseBody.getSignName());
        querySmsSignResponseModel.setCode(querySmsSignResponseBody.getCode());
        querySmsSignResponseModel.setMessage(querySmsSignResponseBody.getMessage());
        querySmsSignResponseModel.setRequestId(querySmsSignResponseBody.getRequestId());

        try {
            String createDate = querySmsSignResponseBody.getCreateDate();
            // 判断创建时间是否为空
            if(!StringVerify.isBlank(createDate)) {
                querySmsSignResponseModel.setCreateDate(DateConvert.stringToDate(createDate, DateTimeFormatEnum.yyyy_MM_dd_HH_mm_ss));
            }
            Integer signStatus = querySmsSignResponseBody.getSignStatus();
            // 判断签名状态是否为空
            if(!IntegerVerify.isBlank(signStatus)) {
                querySmsSignResponseModel.setSignStatus(EnumUtil.valueOfEnum(SendStatusEnum.class, Long.valueOf(signStatus), "getCode"));
            }
        } catch (BasicsException e) {
            throw new AliYunConfigRuntimeException(e.getLocalizedMessage());
        }
        return querySmsSignResponseModel;

    }

    /**
     * 内容转模型
     * @param querySmsSignResponseBody 获取短信签名响应内容
     * @return 获取短信签名响应模型
     */
    public static QuerySmsSignResponseModel bodyToModel(com.aliyun.dysmsapi20170525.models.QuerySmsSignResponseBody querySmsSignResponseBody){
        QuerySmsSignResponseModel querySmsSignResponseModel = new QuerySmsSignResponseModel();
        querySmsSignResponseModel.setReason(querySmsSignResponseBody.getReason());
        querySmsSignResponseModel.setSignName(querySmsSignResponseBody.getSignName());
        querySmsSignResponseModel.setCode(querySmsSignResponseBody.getCode());
        querySmsSignResponseModel.setMessage(querySmsSignResponseBody.getMessage());
        querySmsSignResponseModel.setRequestId(querySmsSignResponseBody.getRequestId());

        try {
            String createDate = querySmsSignResponseBody.getCreateDate();
            // 判断创建时间是否为空
            if(!StringVerify.isBlank(createDate)) {
                querySmsSignResponseModel.setCreateDate(DateConvert.stringToDate(createDate, DateTimeFormatEnum.yyyy_MM_dd_HH_mm_ss));
            }
            Integer signStatus = querySmsSignResponseBody.getSignStatus();
            // 判断签名状态是否为空
            if(!IntegerVerify.isBlank(signStatus)) {
                querySmsSignResponseModel.setSignStatus(EnumUtil.valueOfEnum(SendStatusEnum.class, Long.valueOf(signStatus), "getCode"));
            }
        } catch (BasicsException e) {
            throw new AliYunConfigRuntimeException(e.getLocalizedMessage());
        }
        return querySmsSignResponseModel;
    }
}